# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=bqm
_gemname=$pkgname
pkgver=v1.5.1.r5.ge287280
pkgrel=4
pkgdesc='Download BloudHound query lists, deduplicate entries and merge them in one file.'
arch=('any')
groups=('blackarch' 'blackarch-misc')
url='https://github.com/Acceis/bqm'
license=('MIT')
depends=('ruby')
makedepends=('git')
options=(!emptydirs)
source=("git+https://github.com/Acceis/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $_gemname

  git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

build() {
  cd $_gemname

  gem build "$_gemname.gemspec"
}

package() {
  cd $_gemname

  _gemhome="$(gem env home)"
  _release=$(gem build $_gemname.gemspec | grep Version | cut -d' ' -f4)

  gem install --ignore-dependencies --no-user-install --no-document \
    --no-wrapper -i "$pkgdir/$_gemhome" -n "$pkgdir/usr/bin" \
    "$_gemname-$_release.gem"

  rm "$pkgdir/usr/bin/$pkgname"
  ln -s "$_gemhome/gems/bqm-$_release/bin/$pkgname" "$pkgdir/usr/bin/$pkgname"

  rm -rf "$pkgdir/$_gemhome/cache/$_gemname-$_release.gem"
  find "$pkgdir/$_gemhome/extensions/" -name *.so -delete

  install -Dm 644 "$pkgdir/$_gemhome/gems/$_gemname-$_release/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

